package com.bilibili.juc.volatileList;

import sun.misc.Unsafe;

import java.util.concurrent.TimeUnit;

/**
 * @author zuife
 * @description
 * @since 2024-05-01 08:30:38
 */
public class VolatileSeeDemo {
    volatile static boolean flag = true;

    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println("-----------come in");
            while (flag) {

            }
            System.out.println("-----------flag被是设置为false,程序停止");
        }, "t1").start();
        //暂停几秒钟线程
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        flag = false;
        System.out.println("-----------main线程修改了flag的值为false");
    }
}
